#[derive(Debug)]
pub struct Color(i32, i32, i32);

impl Color {
    fn new(r: i32, g: i32, b: i32) -> Color {
        return Color(r, g, b);
    }
}

#[derive(Debug)]
pub struct Circe {
    pub x: i32,
    pub y: i32,
    pub r: i32,
    des: String,
}

impl Circe {
    fn new(x: i32, y: i32, r: i32, des: String) -> Circe {
        return Circe { x, y, r, des };
    }
    fn des(&mut self, des: String) {
        self.des = des
    }
}

// self 表示 Rectangle 的所有权转移到该方法中，这种形式用的较少
// &self  表示该方法对 Rectangle 的不可变借用 // &self 其实是 self: &Self
// &mut self 表示可变借用,//改变当前结构体

impl Circe {
    pub fn size(&self) -> i32 {
        return self.r * self.r * 3;
    }
}

#[cfg(test)]
mod tests {
    use crate::basex::structx::structx::{Circe, Color};

    #[test]
    fn base() {
        let color = Color::new(1, 2, 3);
        let circe = Circe::new(1, 2, 3, String::from("a"));
        // circe.des("as")
        println!("{:?}", color);
        println!("{:?} {:?}", circe, circe.x);
        let new_circe = Circe {
            // des: String::from("as"), 所有权转义
            x: 1,
            ..circe
        };
        println!("{:#?}", new_circe);
        dbg!(&new_circe);
    }

    #[test]
    fn method() {
        let circe = Circe::new(1, 2, 3, String::from("a"));
        println!("{:?}", circe.size());
        println!("{:#?}", circe.size_map());
    }
}
